/**
 * Created by Administrator on 2016/1/28.
 */
var userDao =require('../dao/userDao');


/**
 * add user
 * @returns {Function}
 */
exports.userAddAction = function(req, res) {
    var user = new Array();
    for(var i=0;i<10;i++){
        user.push({
            name:"user"+(i+1),
            password:"123456"//字段如果不是在model里面定义字段，则不会被录入
        });
    }

     userDao.addUser(user,function(result){
         res.json(result);
     });
}


/**
 * get User List
 * @returns {Function}
 */
exports.userFindAction = function(req, res) {
    var conditions ={};
    userDao.findUser(conditions,function(result){
        res.json(result);
    });
}

exports.userRemoveAction = function(req, res) {
    var conditions ={name : 'user1'};
    userDao.removeUser(conditions,function(result){
        res.json(result);
    });
    //除了要删除user表里的内容，还要删除关联表(user_schoolClass)的内容
}

exports.userUpdateAction = function (req, res) {

    var conditions = {name : 'user9'};
    var update = {$set : {name:"wwwwwww"}}//{$set : {userName:xxx}};
    var options = {upsert : false}//{upsert:false};

    userDao.updateUser(conditions, update, options, function (result) {
        res.json(result);
    });
    //如果要更加关联对象，需要update user_schoolClass表中的userid 和scoolClassId
}
